package com.glinsoft.ticktak.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import com.glinsoft.ticktak.entity.ScheduleRecord;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import lombok.Data;

import org.springframework.beans.BeanUtils;

import java.io.Serializable;

import java.time.LocalDateTime;

import java.util.ArrayList;
import java.util.List;


/**
 * schedule_record
 */
@SuppressWarnings("serial")
@ApiModel("任务调度记录")
@Data
public class ScheduleRecordVo implements Serializable {
    /**  id **/
    @ApiModelProperty(value = "")
    public String id;

    /** 任务ID;table:task； task_id **/
    @ApiModelProperty(value = "任务ID;table:task")
    public String taskId;

    /** 开始时间； start_time **/
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "开始时间")
    public LocalDateTime startTime;

    /** 完成时间； end_time **/
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "完成时间")
    public LocalDateTime endTime;

    /** 执行成功;0:否,1:是； succeed **/
    @ApiModelProperty(value = "执行成功;0:否,1:是")
    public Integer succeed;

    /** 执行参数； parameters **/
    @ApiModelProperty(value = "执行参数")
    public String parameters;

    /** 任务执行返回值； returns **/
    @ApiModelProperty(value = "任务执行返回值")
    public String returns;

    /** 错误信息； error_message **/
    @ApiModelProperty(value = "错误信息")
    public String errorMessage;

    public static ScheduleRecordVo fromPO(ScheduleRecord po) {
        if (po == null) {
            return null;
        }

        ScheduleRecordVo vo = new ScheduleRecordVo();
        BeanUtils.copyProperties(po, vo);

        return vo;
    }

    public static List<ScheduleRecordVo> fromPO(List<ScheduleRecord> pos) {
        if ((pos == null) || (pos.size() == 0)) {
            return null;
        }

        List<ScheduleRecordVo> r = new ArrayList();

        for (ScheduleRecord po : pos) {
            r.add(fromPO(po));
        }

        return r;
    }

    public ScheduleRecord toPO() {
        ScheduleRecord po = new ScheduleRecord();
        BeanUtils.copyProperties(this, po);

        return po;
    }

    public static List<ScheduleRecord> toPO(List<ScheduleRecordVo> vos) {
        if ((vos == null) || (vos.size() == 0)) {
            return null;
        }

        List<ScheduleRecord> r = new ArrayList();

        for (ScheduleRecordVo vo : vos) {
            r.add(vo.toPO());
        }

        return r;
    }
}
